"""
@author: chenzhenhua
@project: auto_jift
@file: doc2docx.py
@time: 2021/9/14 11:20
@desc:
"""

import os

from win32com import client as wc


class Conversion(object):
    def __init__(self, origin_path, out_path):
        """

        :param origin_path: 原始路径
        :param out_path: 输出路径
        """
        self.origin_path = origin_path
        self.out_path = out_path

    def save_doc2docx(self):
        """

        :return:
        """
        word = wc.Dispatch("Word.Application")
        for i in os.listdir(self.origin_path):
            if i.endswith('.doc') and not i.startswith('~$'):
                doc = word.Documents.Open(self.origin_path + i)
                rename = os.path.splitext(i)
                doc.SaveAs(self.out_path + rename[0] + '.docx', 12)  # 12表示docx格式
                doc.Close()
        word.Quit()
